package com.ruoyi.qualityControl.controller;

import com.alibaba.fastjson2.JSONObject;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.logistic.domain.PageInfo;
import com.ruoyi.qualityControl.domain.QcFalseSignComplain;
import com.ruoyi.qualityControl.domain.vo.QcFalseSignComplainVo;
import com.ruoyi.qualityControl.service.QcFalseSignComplainService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RequestMapping("/qc/falseSign")
@RestController
@Api(tags = "质控中心_虚假签收投诉")
public class QcFalseSignComplainController {
    @Autowired
    private QcFalseSignComplainService qcFalseSignComplainService;

    @ApiOperation("查全部")
    @GetMapping("/selectAll")
    public R selectAll() {
        List<QcFalseSignComplain> qcFalseSignComplains = qcFalseSignComplainService.settleAll();
        if (qcFalseSignComplains == null || qcFalseSignComplains.size() == 0) {
            return R.fail("暂无数据");
        } else {
            JSONObject jsonObject = new JSONObject();
            jsonObject.put("list",qcFalseSignComplains);
            jsonObject.put("fields",qcFalseSignComplainService.initTable());
            return R.ok(jsonObject);
        }
    }

    @ApiOperation("添加")
    @PostMapping("/insert")
    public R insert(@RequestBody QcFalseSignComplain qcFalseSignComplain){
        Boolean isAdd = qcFalseSignComplainService.insert(qcFalseSignComplain);
        if (isAdd){
            return R.ok("添加成功");
        }else {
            return R.fail("添加失败");
        }
    }

    @ApiOperation("修改")
    @PostMapping("/update")
    public R update(@RequestBody QcFalseSignComplain qcFalseSignComplain){
        Boolean isUpdate = qcFalseSignComplainService.update(qcFalseSignComplain);
        if (isUpdate){
            return R.ok("修改成功");
        }else {
            return R.fail("修改失败");
        }
    }

    @ApiOperation("删除")
    @PostMapping("/delete")
    public R delete(Integer id){
        Boolean isDelete = qcFalseSignComplainService.deleteById(id);
        if (isDelete){
            return R.ok("删除成功");
        }else {
            return R.fail("删除失败");
        }
    }

    @ApiOperation("搜索")
    @PostMapping("/search")
    public R search(@RequestBody QcFalseSignComplainVo vo) {
        if (vo.getStartTime() == null || vo.getEndTime() == null || vo.getComplainSourceId() == null || vo.getExplainStatusId() == null){
            return R.fail("请输入必要的查询条件");
        }
        List<QcFalseSignComplain> qcFalseSignComplains = qcFalseSignComplainService.search(vo);
        if (qcFalseSignComplains == null || qcFalseSignComplains.size() == 0) {
            return R.fail("暂无数据");
        } else {
            JSONObject jsonObject = new JSONObject();
            jsonObject.put("list",PageInfo.info(qcFalseSignComplains));
            jsonObject.put("fields",qcFalseSignComplainService.initTable());
            return R.ok(jsonObject);
        }
    }
}
